import { getOrderYearExportvolumeByParams, getOrderYearNumByParams, getForexYearRecamountByParams,
    getWebOrderYearExportvolumeByParams, getWebOrderYearNumByParams, getWebForexYearRecamountByParams } from '../../services/workbench/charts';
import {message} from 'antd';
const R = require('ramda');

export default {
    namespace: 'charts',
    state:{
        exportvolumeData: [],
        ordernumData: [],
        forexRecamountData: [],
        userExportvolumeData: [],
        userOrdernumData: [],
        userForexRecamountData: [],
    },
    reducers: {
        /**
         * 刷新state
         * 
         * @param state 
         */
        refreshState(state,{ payload }){
            return {...state, ...payload};
        }
    },
    effects: {
        /**
         * 全年报关完成订单出口额度
         * 
         * @param date
         */
        *getOrderYearExportvolumeByParams({ payload }, { call, put }){
            const res = yield call(getOrderYearExportvolumeByParams, { ...R.omit(['onSuccess', 'onFail'])(payload) });
            if(res && res.data.resultCode === "ok"){
                yield put({
                    type:'refreshState',
                    payload: {
                        exportvolumeData: res.data.content
                    }
                });
            } else {
                if(payload.onFail) payload.onFail();
            }
        },
        /**
         * 全年报关完成订单出口额度(用户维度)
         * 
         * @param date
         */
        *getWebOrderYearExportvolumeByParams({ payload }, { call, put }){
            const res = yield call(getWebOrderYearExportvolumeByParams, { ...R.omit(['onSuccess', 'onFail'])(payload) });
            if(res && res.data.resultCode === "ok"){
                yield put({
                    type:'refreshState',
                    payload: {
                        userExportvolumeData: res.data.content
                    }
                });
            } else {
                if(payload.onFail) payload.onFail();
            }
        },

         /**
         * 全年报关完成订单数量
         * 
         * @param date
         */
        *getOrderYearNumByParams({ payload }, { call, put }){
            const res = yield call(getOrderYearNumByParams, { ...R.omit(['onSuccess', 'onFail'])(payload) });
            if(res && res.data.resultCode === "ok"){
                yield put({
                    type:'refreshState',
                    payload: {
                        ordernumData: res.data.content
                    }
                });
            } else {
                if(payload.onFail) payload.onFail();
            }
        },
        /**
         * 全年报关完成订单数量(用户维度)
         * 
         * @param date
         */
        *getWebOrderYearNumByParams({ payload }, { call, put }){
            const res = yield call(getWebOrderYearNumByParams, { ...R.omit(['onSuccess', 'onFail'])(payload) });
            if(res && res.data.resultCode === "ok"){
                yield put({
                    type:'refreshState',
                    payload: {
                        userOrdernumData: res.data.content
                    }
                });
            } else {
                if(payload.onFail) payload.onFail();
            }
        },

        /**
         * 全年已结汇的外汇收汇金额
         * 
         * @param date
         */
        *getForexYearRecamountByParams({ payload }, { call, put }){
            const res = yield call(getForexYearRecamountByParams, { ...R.omit(['onSuccess', 'onFail'])(payload) });
            if(res && res.data.resultCode === "ok"){
                yield put({
                    type:'refreshState',
                    payload: {
                        forexRecamountData: res.data.content
                    }
                });
            } else {
                if(payload.onFail) payload.onFail();
            }
        },
        /**
         * 全年已结汇的外汇收汇金额(用户维度)
         * 
         * @param date
         */
        *getWebForexYearRecamountByParams({ payload }, { call, put }){
            const res = yield call(getWebForexYearRecamountByParams, { ...R.omit(['onSuccess', 'onFail'])(payload) });
            if(res && res.data.resultCode === "ok"){
                yield put({
                    type:'refreshState',
                    payload: {
                        userForexRecamountData: res.data.content
                    }
                });
            } else {
                if(payload.onFail) payload.onFail();
            }
        },
    },
};